[PATCH 06/25] delete void* is undefined 您所在的位置:网站首页 delete void* isundefined [PATCH 06/25] delete void* is undefined

[PATCH 06/25] delete void* is undefined

2024-06-15 02:01| 来源: 网络整理| 查看: 265

Quick comment on this one - the change looks quite suspicious, so I would encourage deeper code review. Dynamic memory must be allocated and deallocated using consistent pairs (new/delete, malloc/free, new[]/delete[]). Mixing new and free is bad practice and can lead to undefined behavior. Even if for simple POD, Plain Old Data, structures it can work fine, for any complex types it may be generally unpredictable.

I have quickly looked at OpenGl_addnames.cxx and see that allocation in AddNamesetAdd() is done view new :

static TStatus AddNamesetAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k ) { ... data = new TEL_TINT_DATA();

... ((tsm_elem_data)(d.pdata))->pdata = data; ... }

deallocation (in the patch) via free: static TStatus AddNamesetDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k ) { if (data.pdata) free(data.pdata); return TSuccess; }

This is wrong. The better way would be to use detete reinterpret_cast (data.pdata);

or C-style cast: delete (TEL_TINT_DATA*) (data.pdata);

With that, I would recommend a patch rework. Ideally, it would be good to use the memory checker (like Intel Inspector XE or probably Valgrind) to detect inconsistent behavior.

Hope this helps. Roman



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有